# -*- coding:utf-8 -*-
# @FileName : app\api\v1\chat\schemas.py
# @Time     : 2025/11/28
# @Author   : 天空之城
"""Chat API 数据校验模式文件

此模块定义了 Chat API 所需的数据校验模式。
"""
from marshmallow import Schema, fields, validate


class ChatSendRequestSchema(Schema):
    """发送聊天消息请求数据模式"""
    conversation_id = fields.Str(required=True, validate=validate.Length(min=1))
    message = fields.Str(required=True, validate=validate.Length(min=1))


class ChatSendResponseSchema(Schema):
    """发送聊天消息响应数据模式"""
    conversation_id = fields.Str(required=True)
    message = fields.Str(required=True)
    execution_id = fields.Int(required=False, allow_none=True)
    tool_execution_logs = fields.List(fields.Raw(), required=False, default=[])


class TaskExecutionSchema(Schema):
    """任务执行详情数据模式"""
    id = fields.Int(required=True)
    conversation_id = fields.Int(required=True)
    status = fields.Str(required=True)
    summary = fields.Str(required=False, allow_none=True)
    assertion_result = fields.Bool(required=True)
    assertion_reason = fields.Str(required=False, allow_none=True)
    created_at = fields.DateTime(required=True)
    updated_at = fields.DateTime(required=True)


class TaskStepSchema(Schema):
    """任务执行步骤数据模式"""
    id = fields.Int(required=True)
    execution_id = fields.Int(required=True)
    step_number = fields.Int(required=True)
    action_type = fields.Str(required=True)
    description = fields.Str(required=True)
    screenshot_path = fields.Str(required=False, allow_none=True)
    status = fields.Str(required=True)
    created_at = fields.DateTime(required=True)
    updated_at = fields.DateTime(required=True)


class TaskExecutionDetailSchema(Schema):
    """任务执行详情响应数据模式"""
    execution = fields.Nested(TaskExecutionSchema, required=True)
    steps = fields.List(fields.Nested(TaskStepSchema), required=True)


class MessageSchema(Schema):
    """消息数据模式"""
    id = fields.Int(required=True)
    conversation_id = fields.Int(required=True)
    role = fields.Str(required=True)
    content = fields.Str(required=True)
    image_path = fields.Str(required=False, allow_none=True)
    meta_data = fields.Raw(required=False, allow_none=True)
    created_at = fields.DateTime(required=True)


class ChatHistoryResponseSchema(Schema):
    """聊天历史记录响应数据模式"""
    messages = fields.List(fields.Nested(MessageSchema), required=True)